
const state = {
	address:JSON.parse(uni.getStorageSync('address') || '{}'),
	token:uni.getStorageSync('token') || '',
	//用户信息对象
	userinfo:JSON.parse(uni.getStorageSync('userinfo') || "{}"),
	// 重定向的Object对象
	redirectInfo:null,
	//订单编号
	orderList:uni.getStorageSync('order') || []
}

const mutations = {
	//添加订单
	addOrderList(state,order){
		console.log(order)
		state.orderList.push(order);
		this.commit('user/saveOrderList')
	},
	saveOrderList(state){
		console.log(state.orderList)
		uni.setStorageSync('order',state.orderList)
	},
	//更新收货地址
	updateAddress(state,address){
		state.address = address
		this.commit('user/saveAddressToStorage');
	},
	//持久储存地址
	saveAddressToStorage(state){
		uni.setStorageSync('address',JSON.stringify(state.address));
	},
	//储存用户信息
	saveUserInfoToStorage(state){
		uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
	},
	//将user info信息储存到store中的userInfo中
	updateUserInfo(state,userinfo){
		state.userinfo = userinfo
		this.commit('user/saveUserInfoToStorage');
	},
	//保存token
	updateToken(state,token){
		state.token = token
		this.commit('user/saveTokenToStorage');
	},
	saveTokenToStorage(state){
		uni.setStorageSync('token',state.token);
	},
	updateRedirectInfo(state,info){
		state.redirectInfo = info
		console.log(info)
		console.log(state.redirectInfo);
	}
	
}

const getters = {
	addstr(){
		if(!state.address.provinceName){
			return '';
		}else{
			return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
		}
	},
}


export default{
	namespaced:true,
	state,
	mutations,
	getters
}